{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cropped image saved to data/output_image.jpg\n"
     ]
    }
   ],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "\n",
    "class CutImage:\n",
    "    def __init__(self, image_path):\n",
    "        self.image_path = image_path\n",
    "        self.image = self._load_image()\n",
    "    \n",
    "    def _load_image(self):\n",
    "        image = cv2.imread(self.image_path)\n",
    "        if image is None:\n",
    "            raise ValueError(\"Image not found or path is incorrect\")\n",
    "        return image\n",
    "    \n",
    "    def convert_to_garyscale(self):\n",
    "        gray_image = np.dot(self.image[..., :3], [0.299, 0.587, 0.114])\n",
    "        return gray_image\n",
    "    \n",
    "    def crop_top_right_quarter(self, gray_image):\n",
    "        height, width = gray_image.shape\n",
    "        start_row, start_col = 0, 0\n",
    "        end_row, end_col = height // 2, width // 2\n",
    "        cropped_image = gray_image[start_row:end_row, start_col:end_col]\n",
    "        return cropped_image\n",
    "\n",
    "    def process_and_save(self, output_path):\n",
    "        gray_image = self.convert_to_garyscale()\n",
    "        cropped_image = self.crop_top_right_quarter(gray_image)\n",
    "        cv2.imwrite(output_path, cropped_image)\n",
    "        print(f\"Cropped image saved to {output_path}\")\n",
    "\n",
    "input_image = 'data/image.jpg'\n",
    "output_image = 'data/output_image.jpg'\n",
    "\n",
    "testImage = CutImage(input_image)\n",
    "testImage.process_and_save(output_image)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
